﻿using System;
using System.Runtime.Serialization;

namespace Project362.Users
{

    #region Permission Levels

    /// <summary>
    /// The different permission tiers.
    /// </summary>
    public enum PermissionLevel
    {
        tier1 = 1,
        tier2,
        tier3,
        tier4
    }

    #endregion

    [Serializable]
    public class User : ISerializable
    {

        #region Variables

        /// <summary>
        /// The user name.
        /// </summary>
        private string userName;

        /// <summary>
        /// The password.
        /// </summary>
        private string userPassword;

        /// <summary>
        /// The permission level.
        /// </summary>
        private PermissionLevel permissionLevel;

        #endregion
        #region Properties

        /// <summary>
        /// Get or set the user name.
        /// </summary>
        public string UserName
        {
            get { return userName; }
            set { userName = value; }
        }

        /// <summary>
        /// Get or set the user password.
        /// </summary>
        public string Password
        {
            get { return userPassword; }
            set { userPassword = value; }
        }

        /// <summary>
        /// Get or set the user permission level.
        /// </summary>
        public PermissionLevel Permissions
        {
            get { return permissionLevel; }
            set { permissionLevel = value; }
        }

        #endregion
        #region Constructors

        /// <summary>
        /// Creates a new user with the given user name, password, and permission level.
        /// </summary>
        /// <param name="name">The user name.</param>
        /// <param name="password">The password.</param>
        /// <param name="level">The permission level.</param>
        public User(string name, string password, PermissionLevel level)
        {
            this.userName = name;
            this.userPassword = password;
            this.permissionLevel = level;
        }

        /// <summary>
        /// Creates a new user from a serialized stream.
        /// </summary>
        public User(SerializationInfo info, StreamingContext stream)
        {
            this.userName = (string)info.GetValue("UserName", typeof(string));
            this.userPassword = (string)info.GetValue("Password", typeof(string));
            this.permissionLevel = (PermissionLevel)info.GetValue("Permissions", typeof(PermissionLevel));
        }

        #endregion
        #region Serialize Object

        /// <summary>
        /// Serializes this user to a binary file.
        /// </summary>
        public void GetObjectData(SerializationInfo info, StreamingContext stream)
        {
            info.AddValue("UserName", userName);
            info.AddValue("Password", userPassword);
            info.AddValue("Permissions", permissionLevel);
        }

        #endregion

    }
}
